﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace BDS3M.Admin.Controls
{
    public partial class ViewHoiDap : System.Web.UI.UserControl
    {
        public string hoten;
        public string diachi;
        public string dienthoai;
        public string email;
        public string tieude;
        public string title;
        public string description;
        public string traloi;
        public string active;
        public string date;
        public int id;
        ListItem lt;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["id"] != null)
            {
                id = Convert.ToInt32(Request.QueryString["id"]);
                DataTable dt = DAL.DCollector.DBCollector.Instance.StoredSelectAllTableWhereID("tbl_HoiDap", "HoiDap_ID", id.ToString());
                hoten = dt.Rows[0]["HoiDap_HoTen"].ToString();
                diachi = dt.Rows[0]["HoiDap_DiaChi"].ToString();
                dienthoai = dt.Rows[0]["HoiDap_DienThoai"].ToString();
                email = dt.Rows[0]["HoiDap_Email"].ToString();
                tieude = dt.Rows[0]["HoiDap_TieuDe"].ToString();
                title = dt.Rows[0]["HoiDap_Title"].ToString();
                description = dt.Rows[0]["HoiDap_NoiDung"].ToString();
                traloi = dt.Rows[0]["HoiDap_TraLoi"].ToString();
                active = dt.Rows[0]["HoiDap_Active"].ToString();
                date = dt.Rows[0]["HoiDap_Date"].ToString();
                txtHoten.Text = hoten;
                txtDiachi.Text = diachi;
                txtDienthoai.Text = dienthoai;
                txtEmail.Text = email;
                txtTitle.Text = title;
                txtDescription.Text = description;
                txtDate.Text = date;
                txtTraloi.Text = traloi;
            }
        }

        protected void lbtDelete_Click(object sender, EventArgs e)
        {
            id = Convert.ToInt32(Request.QueryString["id"]);
            DAL.DCollector.DBCollector.Instance.StoredProcedureDeleteByRows("tbl_HoiDap", "HoiDap_ID", id.ToString());
            Response.Redirect("/Admin/Index.aspx?panel=7&sub=24");
        }

        protected void btnUpdateSlide_Click(object sender, EventArgs e)
        {
                if (txtTraloi.Text != "")
                {
                    DAL.DHelpers.Column[] cl = new DAL.DHelpers.Column[2];
                    cl[0] = new DAL.DHelpers.Column("HoiDap_TraLoi", txtTraloi.Text, DAL.DHelpers.DataType.DataTypeSql.Nvarchar);
                    cl[1] = new DAL.DHelpers.Column("HoiDap_Active", "1", DAL.DHelpers.DataType.DataTypeSql.Nvarchar);
                    string[] colWhere = new string[1];
                    colWhere[0] = "HoiDap_ID";

                    object[] colValue = new object[1];
                    colValue[0] = id;

                    DAL.DCollector.DBCollector.Instance.Update("tbl_HoiDap", cl, colWhere, colValue);
                    Response.Redirect("/Admin/Index.aspx?panel=7&sub=24");
                }
                else
                {
                    Response.Write("<script>alert('Không thể để trả lời trống');</scipt>") ;
                }
        }
    }
}